package com.jvtd.nettyim.im.serialize.impl;

import com.alibaba.fastjson.JSON;
import com.jvtd.nettyim.im.serialize.SerializeAlgorithm;
import com.jvtd.nettyim.im.serialize.Serializer;


/**
 * @author Created by neal.zhang
 * @date 2020/5/27 - 20:11
 */
public class JSONSerializer implements Serializer {

    @Override
    public byte getSerializerAlgorithm() {
        return SerializeAlgorithm.JSON;
    }

    @Override
    public byte[] serialize(Object obj) {
        return JSON.toJSONBytes(obj);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {
        return JSON.parseObject(bytes,clazz);
    }
}
